package net.neptech.aop;

import net.neptech.exception.BusinessException;
import net.neptech.vm.ResponseResult;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
/**
 * @Author: liyuxiang
 * @Date: 2025/7/31 17:00
 * @Description: 处理远程调用中触发的异常
 */
public class FeignResponseHandleAspect {
    @Around("@annotation(net.neptech.annotation.FeignResponseHandle)")
    public Object handleFeignResponse(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = joinPoint.proceed();
        if (result instanceof ResponseResult<?> response) {
            if (response.getCode() != 200) {
                throw new BusinessException(response.getCode(),response.getMsg());
            }
            return response;
        }
        return result;
    }
}